package org.vm.cmbcdirect.manager.dao.impl;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.vm.cmbcdirect.manager.dao.MybatisDaoBase;
import org.vm.cmbcdirect.manager.dao.UserDao;
import org.vm.cmbcdirect.manager.model.User;

import java.util.List;

/**
 * Created by hsrj05 on 2016/3/18.
 */
@Repository("userDao")
public class UserDaoImpl extends MybatisDaoBase<User> implements UserDao {

    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    public User queryById(int id) {
        return (User) sqlSessionTemplate.selectOne("user.queryById", id);
    }

    public void save(User u) {
        sqlSessionTemplate.insert("user.insert-user", u);
    }

    public void update(User u) {
        sqlSessionTemplate.update("user.update-user", u);
    }

    public void delete(Integer id) {
        sqlSessionTemplate.delete("user.delete-user", id);
    }

    public List<User> queryAll() {
        List<User> users = sqlSessionTemplate.selectList("user.queryAll");
        return users;
    }
}
